package com.byxy.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.byxy.dao.OrderDao;
import com.byxy.entity.Order;
@Repository
public class OrderDaoImpl implements OrderDao {
	@Resource
	private SessionFactory sessionFactory;

	@Override
	public void add(Order s) {
		sessionFactory.getCurrentSession().save(s);
		
	}

	@Override
	public void delete(Order s) {
		sessionFactory.getCurrentSession().delete(s);
		
	}

	@Override
	public void update(Order s) {
		sessionFactory.getCurrentSession().update(s);
		
	}

	@Override
	public List<Order> find() {
		String hql = "from " + OrderDao.class.getSimpleName();
		return sessionFactory.getCurrentSession().createQuery(hql).list(); 
	}

	@Override
	public List<Order> find(int pos, int rows) {
		String hql = "from" + OrderDao.class.getSimpleName();
		return sessionFactory.getCurrentSession().createQuery(hql)
				.setFirstResult(pos).setMaxResults(rows).list();
	}

	@Override
	public Order get(String id) {
		return (Order) sessionFactory.getCurrentSession().load(Order.class, id);
	}

	@Override
	public long count() {
		String hql = "select count(u) from" + OrderDao.class.getSimpleName()
				+"u";
		return(long)sessionFactory.getCurrentSession()
				.createQuery(hql).uniqueResult();
	}
	
}
